/**
 * Created by Administrator on 2017/7/13.
 */
define(['jquery', "vue", 'ks-spa'], function ($, Vue,spa) {
    var vue = new Vue({
        el: '#pages',
        data: {},
        methods: {
            withdraw: function () {
                var money = $('#money').val();
                if (money === '') {
                    mui.alert('请输入金额');
                    return;
                }
                if(parseFloat(money)<0){
                    mui.alert('提现金额错误！');
                    return;
                }
                if (parseFloat(money) > balance) {
                    mui.alert('提现金额过大');
                    return;
                }
                $.ajax({
                    type: 'POST',
                    data: {money: money},
                    url: withdraw_submit_url,
                    dataType: 'json',
                    beforeSend: function (xhr, settings) {
                        spa.showLoading();
                    },
                    success: function (res, status, xhr) {
                        spa.hideLoading();
                        if (res.code === 1) {
                            mui.alert(res.msg, "系统提示", function () {
                                window.location.href = redirect_url;
                            });
                        } else {
                            mui.alert(res.msg);
                        }
                    },
                    error: function (xhr, errorType, error) {
                        spa.hideLoading();
                        mui.toast('网络异常，请稍后重试');
                    },
                    complete: function (XMLHttpRequest, textStatus) {
                        spa.hideLoading();
                    }
                });
                // spa.showLoading();
                // $.ajax({
                //     url: withdraw_submit_url,
                //     data: {money: money},
                //     success: function (res) {
                //         spa.hideLoading();
                //         if (res.code === 1) {
                //             mui.alert(res.msg, "系统提示", function () {
                //                 window.location.href = redirect_url;
                //             });
                //             // setTimeout("window.location.href='"+redirect_url+"'",1000)
                //         } else {
                //             mui.alert(res.msg);
                //         }
                //     }
                // })
            }
        }
    });
});